package com.shop.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.shop.entity.Business;
import com.shop.entity.User;
import com.shop.service.BusinessService;
import com.shop.service.UserService;

/**
 * Servlet implementation class Login
 */
@WebServlet("/BusinessLogin")
public class BusinessLogin extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BusinessLogin() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
    private BusinessService BusinessService = new BusinessService();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		// TODO Auto-generated method stub
		

		// 获取用户的用户名和密码
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		Business business = new Business();
		business.setUsername(username);
		business.setPassword(password);
		
		request.getSession().setAttribute("username", business);
		
		
	
		
		String msg = "";
	
		if (BusinessService.isExist(business) &&username != "" && password != "") {
			
			// 在数据库中是否能够查询的到
			List<Business> list = BusinessService.getAllBusiness();
			msg = "登录成功";
			request.setAttribute("msg", msg);
			request.setAttribute("list", list);
			request.getRequestDispatcher("businesslist").forward(request, response);
			return;
		
		}else{
			msg = "请输入正确的账户名和密码";
			request.setAttribute("msg", msg);
			request.getRequestDispatcher("BusinessLogin.jsp").forward(request, response);
			return;
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
